#ifndef MYCLIENTSOCKET_H
#define MYCLIENTSOCKET_H

#include <QObject>
#include <QTcpSocket>
#include <QByteArray>

class MyClientSocket : public QObject
{
    Q_OBJECT
public:
    explicit MyClientSocket(QObject *parent = nullptr);
    //连接服务器
    void connectToServer(const QString &ip,int port);
    //发送数据
    int writeBytes(const QByteArray &data);
    //接收数据

signals:
    void dataRecv(const QByteArray &data);
public slots:
    //处理通信数据
    void handleReadSlot();
private:
    QString m_ip;
    int m_port;
    QTcpSocket *m_socket;
    //缓冲区
    QByteArray m_buffer;
};

#endif // MYCLIENTSOCKET_H
